#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QHostAddress>
#include <QUdpSocket>
#include <QTime>
#include <QDebug>
#include "vector"
#include <iostream>
#include <QMessageBox>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QUdpSocket *udpSocket;

    QString host = "";
    qint16 port = 0;//远程主机端口
    QHostAddress local_ip;
    quint16 local_port=0;//本机端口
    bool isConnected=false;

    //通过QDatastream组装成数据帧
    typedef struct
    {
        unsigned int head=0x55555555;			//索引 0x55555555
        unsigned int count;			//计数
        float x;					//
        float y;					//
        float r;					//
        //unsigned int tail=0xaaaaaaaa;		//AAAAAAAA
    }SEND_TO_PLC;

    double check(SEND_TO_PLC);

    QByteArray serializeFrame(SEND_TO_PLC);

    //模拟下为系统向上位机发送数据

private slots:

    void readMsg();

    void on_internet_connect_clicked();

    void on_internet_disconnect_clicked();

    void writeReal(QDataStream& out, float f);

private:
    Ui::MainWindow *ui;

};
#endif // MAINWINDOW_H
